package com.bw.shop2208a.cate

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.shop2208a.entity.GoodsEntity
import com.bw.shop2208a.entity.GoodsTypeEntity
import com.bw.shop2208a.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CateViewModel : BaseViewModel(){
    val successGoods = MutableLiveData<GoodsEntity>()
    val failGoods = MutableLiveData<String>()

    fun getGoods(category_id: Int, currentPage: Int, pageSize: Int) {
        viewModelScope.launch {
            try {
                successGoods.value = apiservice.getGoods(category_id, currentPage, pageSize)
            } catch (e: Exception) {
                failGoods.value = e.message
            }
        }
    }

    val successGoodsType = MutableLiveData<GoodsTypeEntity>()
    val failGoodsType = MutableLiveData<String>()

    fun getGoodsType() {
        viewModelScope.launch {
            try {
                successGoodsType.value = apiservice.getGoodsType()
            } catch (e: Exception) {
                failGoodsType.value = e.message
            }
        }
    }
}